package cn.com.ghy.android.service;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.com.ghy.android.bean.LoginInfoBean;
import cn.com.ghy.android.bean.LoginInfoBeanParser;
import cn.com.ghy.android.util.CommonStatic;
import cn.com.ghy.android.util.CommonUtil;

/**
 * @软件著作权:金红叶纸业集团有限公司
 * @系统名称:SFA系统
 * @Description:登录服务,并解析WebService的返回值
 * @author wuz  @date 2011-5-11 15:10:13
 * @版本历史:v1.0
 * @Copyright:Copyright (c) 2011-2012 
 */

public class LoginOpeService {
	private String url = CommonStatic.URL_HEAD + "loginope_ar.asmx";
	private String methodName = "";
	private Map<String, String> params = null;
	
	private static final String USERID = "userid";
	private static final String USERPWD = "userpwd";
	private static final String NEWPWD = "newpwd";
	 
	public List<LoginInfoBean> UserLogin(String userid, String userpwd) throws Exception {
		methodName = "UserLogin";
		params = new HashMap<String, String>();
		params.put(USERID, userid);
		params.put(USERPWD, userpwd);
		String result = null;
		result = HttpService.callWS(url, methodName, params);
		byte[] buffer = org.kobjects.base64.Base64.decode(result);
		byte[] info = CommonUtil.decompressByteArray(buffer);
		InputStream in = new ByteArrayInputStream(info);
		List<LoginInfoBean> list = LoginInfoBeanParser.parseXML(in);
		in.close();
		CommonUtil.checkListNull(list);
		return list;
	}
	
	public String UserPwdEdit(LoginInfoBean loginInfo, 
			String userpwd, String newpwd) throws Exception {
		methodName = "UserPwdEdit";
		params = new HashMap<String, String>();
		params.put(USERID, loginInfo.getPernr());
		params.put(USERPWD, userpwd);
		params.put(NEWPWD, newpwd);
		String result = null;
		result = HttpService.callWS(url, methodName, params);
		return result;
	}
	
	public String LoginAndroidVer() throws Exception {
		methodName = "LoginAndroidVer";
		String result = null;
		result = HttpService.callWS(url, methodName, params);
		return result;
	}
}
